import requests
from bs4 import BeautifulSoup


if __name__ == "__main__":

    headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 QQBrowser/4.4.106.400',
    'Connection': 'keep-alive',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'}

    html=requests.get('https://car.autohome.com.cn/price/brand-33.html',headers=headers)
    #html.encoding = 'gb2312'
    print(html.text)
    soup = BeautifulSoup(html.text,'html.parser')
    #xx=soup.find('h2','class_=fn-left name')
    #xx=soup.find_all('h2')
    #print(xx)
    tt=soup.find_all('h2')
    print(tt)
    #yy=xx.find('a')
    #print(yy['href'])  #出错，如何能取到这个h2中的汽车品牌名称呢？
    '''
    <h2 class="fn-left name"><a href="/price/brand-33.html">奥迪</a></h2>
    '''